//
//  SettingsViewController.m
//  跨界收
//
//  Created by Allen on 2018/10/27.
//  Copyright © 2018年 gztx. All rights reserved.
//

#import "SettingsViewController.h"
#import "HelpCenterViewController.h"
#import "QuestionViewController.h"

@interface SettingsViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *setTableView;
@property (nonatomic, strong) NSArray *titles;
@end

@implementation SettingsViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    self.setTableView.delegate = self;
    self.setTableView.dataSource = self;
    _titles = @[@"语音/通知",@"文字/通知",@"实时交易更新",@"帮助中心",@"意见反馈",@"清除本地缓存",@"版本"];
    
    // Do any additional setup after loading the view from its nib.
}
#pragma mark -- UITableViewDelegate/DataSource --
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
    UIButton *logoutBtn  = [[UIButton alloc]initWithFrame:CGRectMake((SCREEN_WIDTH - 260)/2.0, 40.0, 260, 50.0)];
    [logoutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [logoutBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    logoutBtn.layer.masksToBounds = YES;
    logoutBtn.layer.cornerRadius = 3.0;
    logoutBtn.backgroundColor = [UIColor cz_colorWithHex:0x219fdb];
    [logoutBtn  addClickTargetBlock:^(UIButton *sender) {
        NSLog(@"tuichudenglu");
    }];
    [view addSubview:logoutBtn];
    return view;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titles.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    cell.textLabel.text = _titles[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    switch (indexPath.row) {
        case 0:{
            UISwitch *s1 = [[UISwitch alloc]init];
            [s1 setOn:YES];
            
            [s1 addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
            s1.tag = indexPath.row;
            cell.accessoryView = s1;
        }
            break;
        case 1:{
            UISwitch *s2 = [[UISwitch alloc]init];
            [s2 addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
            s2.tag = indexPath.row;
            [s2 setOn:YES];
            cell.accessoryView = s2;
        }
            break;
        case 2:{
            UISwitch *s3 = [[UISwitch alloc]init];
            [s3 addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
            s3.tag = indexPath.row;
            [s3 setOn:YES];
            cell.accessoryView = s3;
        }
            break;
        case 3:{
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
            break;
        case 4:{
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
            break;
        case 5:{
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        }
            break;
        case 6:{
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
            CFShow((__bridge CFTypeRef)(infoDictionary));
            NSString *appV = [NSString stringWithFormat:@"V%@",infoDictionary[@"CFBundleShortVersionString"]];
            cell.detailTextLabel.text = appV;
            
        }
            break;
            
        default:
            break;
    }
    
    return cell;
}
- (void)switchAction:(UISwitch *)sw
{
    switch (sw.tag) {
        case 0:
        {
            
        }
            break;
        case 1:
        {
            
        }
            break;
        case 2:
        {
            
        }
            break;
            
        default:
            break;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 3:
        {
            HelpCenterViewController *helpVC = [[HelpCenterViewController alloc]initWithNibName:@"HelpCenterViewController" bundle:nil];
            [self.navigationController pushViewController:helpVC animated:YES];
        }
            break;
        case 4:
        {
            QuestionViewController *qVC = [[QuestionViewController alloc]initWithNibName:@"QuestionViewController" bundle:nil];
            [self.navigationController pushViewController:qVC animated:YES];
        }
            break;
        case 5://clear cache
        {
           
        }
            break;
            
        default:
            break;
    }
}
@end
